import java.util.Comparator;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-10-13
 * Time: 16:54
 */
class CardComparator implements Comparator<Card> {
    @Override
    public int compare(Card o1, Card o2) {
        if(o1 == o2) return 0;
        if(o1 == null || o2 == null) return -1;
        return o1.rank - o2.rank;
    }
}
class Card implements Comparable<Card>{
    public String suit;
    public int rank;

    public Card(String suit, int rank) {
        this.suit = suit;
        this.rank = rank;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return rank == card.rank && Objects.equals(suit, card.suit);
    }

    @Override
    public int compareTo(Card o) {
        if(o == null) return 1;
        return this.rank - o.rank;
    }
}
public class Test1 {
    public static void main(String[] args) {
        Card card1 = new Card("hongtao",1);
        Card card2 = new Card("hongtao",1);
        Card card3 = card1;
        System.out.println("------==------");
        System.out.println(card1 == card2);
        System.out.println(card1 == card3);
        System.out.println("----equals----");
        System.out.println(card1.equals(card2));
        System.out.println("---compareTo---");
        System.out.println(card1.compareTo(card2));
        System.out.println("----compare----");
        CardComparator cardComparator = new CardComparator();
        System.out.println(cardComparator.compare(card1, card2));
    }
}
